package com.probox.common.entity.service.product.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

import com.probox.common.core.enums.DataStatus;
import com.probox.common.core.enums.ProductLogType;
import com.probox.common.core.exception.ProductException;
import com.probox.common.core.utils.SecurityUtils;
import com.probox.common.core.utils.StringUtils;
import com.probox.common.entity.domain.product.vo.ProductLogQuery;
import com.probox.common.entity.domain.product.vo.ProductLogVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.probox.common.entity.mapper.product.ProductsLogMapper;
import com.probox.common.entity.domain.product.ProductLog;
import com.probox.common.entity.service.product.IProductLogService;

/**
 * 产品操作日志Service业务层处理
 *
 *
 * @date 2021-05-28
 */
@Service
public class ProductLogServiceImpl extends ServiceImpl<ProductsLogMapper, ProductLog> implements IProductLogService {
    @Autowired
    private ProductsLogMapper productsLogMapper;




    /**
     * 查询产品操作日志列表
     *
     * @param productLogQuery 商品日志查询
     * @return 产品操作日志
     */
    @Override
    public List<ProductLogVo> queryList(ProductLogQuery productLogQuery) {
        if (ObjectUtil.isEmpty(productLogQuery.getProductUid())) {
           throw new ProductException("商品数据有异常,请刷新页面！");
        }
        return productsLogMapper.queryLogList(productLogQuery);
    }

    /**
     * 新增产品操作日志
     *
     * @param productLog 产品操作日志
     * @return 结果
     */
    @Override
    public void insertProductsLog(ProductLog productLog) {
        productLog.setPlatform(SecurityUtils.getPlatformId());
        productLog.setCreateUid(SecurityUtils.getUserId());
        productLog.setCreateName(SecurityUtils.getUsername());
        boolean save = this.save(productLog);
        if(!save) throw new ProductException("操作失败,请稍后再试！");
    }

    /**
     *  获取驳回信息
     * @param productUid
     * @return
     */
    @Override
    public String getLog(Long productUid){
        ProductLog log = productsLogMapper.getLog(productUid);
        if(ObjectUtil.isEmpty(log)) return "";
        return log.getDetailInfo();
    }

}
